import QtQuick 2.0
import QtQuick.Controls 1.0
import 'FileView' as FileView



ApplicationWindow {
    id: window
    visible: true
    width: 640
    height: 480
    title: qsTr("PQFM")

    Rectangle {
        id: line
        width: 2
        color: 'black'
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: parent.top
        anchors.bottom: parent.bottom

    }

    Topper {
        id: topper
        anchors.top: parent.top
        anchors.left: parent.left
        anchors.right: parent.right

    }

    Footer {
        id: footer
        anchors.bottom: parent.bottom
        anchors.left: parent.left
        anchors.right: parent.right


    }
    Panel {
        id: panelLeft
        anchors.left: parent.left
        anchors.right: line.left
        anchors.top: topper.bottom
        anchors.bottom: footer.top
        onPreview: window.doPreview(source, panelRight)
    }
    Panel {
        id: panelRight
        anchors.right: parent.right
        anchors.left: line.right
        anchors.top: topper.bottom
        anchors.bottom: footer.top
        onPreview: window.doPreview(source, panelLeft)

    }
    function doPreview(source, canvas) {
        console.log('source:', source);
        preview.anchors.fill = canvas;
        preview.source = source;
    }

    FileView.View {
        id: preview
        anchors.fill: parent
        anchors.margins: 5
        visible: false

    }


    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                text: qsTr("&Open")
                onTriggered: console.log("Open action triggered");
            }
            MenuItem {
                text: qsTr("Exit")
                onTriggered: Qt.quit();
            }
        }
    }

    /*FilesModel {
        id: fm

       // rootPath: "c:/"

        Component.onCompleted: {
            //fm.setRootPath("c:/");
            //mdirModel->setFilter(QDir::AllDirs | QDir::NoDotAndDotDot);
        }
    }*/

   /* FolderListModel {
        id: folderModel
        //  nameFilters: ["*.qml"]
        folder: "file:///c:"
        onFolderChanged: {
            console.log("folder > ", folderModel.folder);
        }
        onParentFolderChanged: {
            console.log("parentFolder > ", folderModel.parentFolder);
        }
    }

    ListView {

        anchors.fill: parent

        model: folderModel // fm // simplaModel
        delegate:     Text {
            text: fileName
            MouseArea {
                anchors.fill: parent
                onClicked: {
                    var f = folderModel.folder.toString();

                    console.log(typeof(f));


                    if(f.substring(f.length-1) != "/")
                        //                    if(f.right(1) != "/")
                    {
                        f += "/";
                    }
                    f += fileName;
                    folderModel.folder = f;
                }
            }
        }

    }*/

}

